package com.webtech.chidiya;

import com.webtech.utils.Utils;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

public class OptionsActivity extends Activity implements OnClickListener {
	/** Called when the activity is first created. */

	private TextView newGameView;
	private TextView settingsView;
	private TextView quickView;
	private TextView scoreView;
	private TextView instructionView;
	private TextView rateView;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_options);

		newGameView = (TextView) findViewById(R.id.newGameView);
		newGameView.setOnClickListener(this);

		settingsView = (TextView) findViewById(R.id.settingsView);
		settingsView.setOnClickListener(this);

		quickView = (TextView) findViewById(R.id.quickView);
		quickView.setOnClickListener(this);

		scoreView = (TextView) findViewById(R.id.scoreView);
		scoreView.setOnClickListener(this);

		instructionView = (TextView) findViewById(R.id.instructionView);
		instructionView.setOnClickListener(this);

		rateView = (TextView) findViewById(R.id.rateView);
		rateView.setOnClickListener(this);
		
		String game_level = SettingPrefs.getGameLevel(this);
		Log.i("DREG", "Game Level ="+game_level);
	}

	private void runAnimation(TextView textView) {
		Animation anim = AnimationUtils.loadAnimation(this, R.anim.set);
		anim.reset();
		textView.clearAnimation();
		textView.startAnimation(anim);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.newGameView:
			runAnimation(newGameView);
			break;
		case R.id.settingsView:
			runAnimation(settingsView);
			Intent intent = new Intent(OptionsActivity.this, SettingPrefs.class);
			startActivity(intent);
			break;
		case R.id.quickView:
			runAnimation(quickView);
			break;
		case R.id.scoreView:
			runAnimation(scoreView);
			break;
		case R.id.instructionView:
			runAnimation(instructionView);
			break;
		case R.id.rateView:
			runAnimation(rateView);
			rateApplication();
			break;
		default:
			break;
		}
		Utils.play(OptionsActivity.this, R.raw.button_click_sound);

	}
	
	private void rateApplication() {
		Uri uri = Uri.parse("market://details?id=" + getPackageName());
		Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
		try {
			startActivity(goToMarket);
		} catch (Exception e) {
			Utils.showAlertMessage(this, android.R.drawable.ic_dialog_alert,
					"Oops ! !",
					"It seems the application is not launched in market");
		}
	}
}